<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 600px;
            margin: 100px auto;
        }

        .message {
            display: inline-block;
            font-style: 12px;
            color: #999;
            padding-left: 20px;
        }

        .messageAfter {
            color: red;
        }

        .messageOK {
            color: green;
        }
    </style>
</head>

<body>
    <div class="register">
        <input type="password" class="ipt">
        <p class="message">请输入密码6~16位</p>
    </div>

    <script>
        var input = document.querySelector('input');
        var msg = document.querySelector('.message');
        input.onblur = function () {
            if (input.value.length < 6 || input.value.length > 16) {
                msg.innerHTML = '❌请输入正确的密码格式:6~16位';
                msg.className = 'message messageAfter';
            } else {
                msg.innerHTML = '✅格式正确';
                msg.className = 'message messageOK';
            }

        }
    </script>
</body>

</html>